<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>斯匹克英语评价系统</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/api/css/style.css" />
    <script src="__STATIC__/api/js/flexible.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC__/api/js/zepto.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC__/plugs/jquery-3.4.1/jquery-3.4.1.min.js"></script>

</head>

<body>
<!--返回-->
<div class="top">
<!--    <i></i>-->
    斯匹克英语评价系统
</div>
<form>
<div class="form-box">
    <!--具体说说看-->
    <div class="jtssk">
        <p class="title"><span>-</span>具体说说看<span>-</span></p>
        <div class="items">
            <input type="hidden" value="{$Request.param.users_id}" name="users_id">
            <input type="hidden" value="{$Request.param.template_id}" name="template_id"  >
            <input type="hidden" value="{$row.qr_user_id}" name="qr_user_id"  >
            <input type="hidden" value="" name="scores"  >
            <input type="hidden" value="" name="star_names"  >
            {if $row.star_names}
            {foreach $row.star_names as $ko=>$vo}

            <div class="item">
                <span>{$vo}</span>
                <div class="star">
                    <span class="off" name="{$vo}" val="{$ko}"></span>
                    <span class="off" name="{$vo}" val="{$ko}"></span>
                    <span class="off" name="{$vo}" val="{$ko}"></span>
                    <span class="off" name="{$vo}" val="{$ko}"></span>
                    <span name="{$vo}" val="{$ko}"></span>
                </div>
            </div>
            {/foreach}
            {/if}
        </div>
    </div>
    <!--评价内容    -->
    {if in_array('评价内容',$row.fields)}
    <div class="remark">
        <textarea name="content" placeholder="说点什么吧..."></textarea>
    </div>
    {/if}

    <div class="remark">
        <label class="cell-item">
            <label class="cell-right">
                <input type="radio" value="2" name="isanonymous"  >
                <i class="cell-checkbox-icon"></i>
            </label>
            <span class="cell-left">匿名评价</span>
        </label>
    </div>
    <div class="submit">
        <button id="submit" lay-submit lay-filter="sub">提交</button>
    </div>
<!--    <div class="layui-form-item">-->
<!--        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="sub">登录</button>-->
<!--    </div>-->

</form>


</body>

</html>
<script type="text/javascript">
    // var services  = {:json_encode($row.fields)};//标签
    $("[name='star_names']").val({:json_encode($row.star_names)});//五星);
    $('.star span').click(function () {
        var arr = [];
        var val = $("[name='scores']").val();
        if(val){
            arr = val.split(',');
        }

        $(this).parent().find('span').removeClass('on');
        var index = $(this).index();
        // alert($(this).attr('name'));return false;
        var zb_name = $(this).attr('name');
        var zb_val = $(this).attr('val');
        arr[zb_val] = $(this).index() + 1;
        $(this).parent().find('span').each(function () {
            if (index < 0) {
                return;
            }
            $(this).addClass('on');
            index--;
        });

        console.log(arr);
        console.log(JSON.stringify(arr))//JSON.stringify(arr)
        // var jsonText= JSON.stringify (str);// 把一个对象转换成 json 字符串
        //
        // str=JSON.parse (jsonText);// 把一个 json 字符串解析成对象
        // console.log(star_name);return false;
        // $("[name='scores']").val(arr);
        $("[name='scores']").val( arr);
    });

    // $('.tags ul li').click(function () {
    //     $(this).toggleClass('on')
    // });
    // $('#submit').click(function () {
        layui.use([ 'element', 'jquery', 'laydate', 'form'],function() {
            var $ = layui.jquery;
            var element = layui.element;
            var laydate = layui.laydate;
            var form = layui.form;
            //监听提交事件
            form.on('submit(sub)', function(data){
                // console.log(data);return false;
                var fields=$(data.form).serializeArray();// serialize
                var ret = true;
                var msg = '';
                $.each(fields, function(index, value) {
                    // alert(index + ': ' + value.name);

                    if(value.name == "scores" && value.value == ''){

                        ret = false;
                        msg = '请进行打分';
                        return false;
                    }
                    if(value.name == "content" && value.value == ''){
                        ret = false;
                        msg = '请进行文字评价';
                        return false;
                    }

                    if((value.name == "images" && value.value == '') || (value.name == "videos" && value.value == '')){
                        ret = false;
                        msg = '请上传图片或者视频';
                        return false;
                    }
                });
                if(ret == false){
                    layer.msg(msg);return false;
                }
                //获取请求数据
                // var oldPwd = data.field.oldPwd;
                // var newPwd = data.field.newPwd;
                // var confirmPwd = data.field.confirmPwd;
                //使用ajax发送请求
                $.ajax({
                    url:"/api/evaluation.elist/addEvaluate",
                    type:"post",
                    data:fields,
                    dataType:"json",
                    success:function(data){
                        layer.msg(data.msg);
                    }
                });
                return false;  //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
        //
    // });
</script>
